#include "config.h"

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "constant.h"
#include "ast_peg.h"
#include "CmdBase.h"

using namespace std;

CCmdBase::CCmdBase()
{
   init();
}

CCmdBase::~CCmdBase()
{
   init();
}

void CCmdBase::release()
{

}

void CCmdBase::init()
{
   mCmdtype = cmd_type_unknown;
   mEventtype = cmd_event_unknown;
   memset( mPrivilege, 0, 32 );
   memset( mChannel, 0, 32 );
}
 
/* Command Parse */
void *CCmdBase::parse( char * aCommandStr )
{
   char * sTmp   = NULL;
   char * sStart = NULL;
   
   sTmp = aCommandStr;
   
   if( privilege_f::Matches( sTmp, sStart ) )
   {
      memset( mPrivilege, 0, 32 ); 
      memcpy( mPrivilege, sStart + 11, ( sTmp - sStart - 13 ) );
   }
   else
   {
      /* do nothing */
   }

   if( channel_f::Matches( sTmp, sStart ) )
   {
      memset( mChannel, 0, 32 ); 
      memcpy( mChannel, sStart + 9, ( sTmp - sStart - 11 ) );
   }
   else
   {
      /* do nothing */
   }

   return this;
}

void CCmdBase::line_print_dbg( char *aFmts, ... )
{
    va_list sAp;
    va_start( sAp,aFmts);
    vprintf( aFmts, sAp);
    va_end( sAp);
}

cmd_type CCmdBase::getCmdType()
{
    return mCmdtype;
}
void CCmdBase::setCmdType( cmd_type aType )
{
    mCmdtype = aType;
}
event_type CCmdBase::getEventType()
{
    return mEventtype;
}
void CCmdBase::setEventType( event_type aType )
{
    mEventtype = aType;
}
